//============================================================================
// Name        : ms009.cpp
// Author      : Tadas
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include "lib.h"

using namespace std;

double func1(double x, double y){
	return x*x +2*x + 3;
}

double fInt(double x){
	return x*x*x/3 + x*x + 3*x;
}

int main() {
	
	double h = 0.1;
	double x[] = {0.0, 0.1, 0.2, 0.3, 0.4};
	double y[] = {0.0, 0.0, 0.0, 0.0, 0.0};
	double y1[] = {0.0, 0.0, 0.0, 0.0, 0.0};
	
	int n = sizeof(x)/sizeof(double);
	
	for(int i = 1; i < n; i++){
		y[i] = stepRK4(x[i - 1], y[i - 1], h, func1);
		y1[i] = stepRK1(x[i - 1], y1[i - 1], h, func1);
		
		cout << "RK4: "<< y[i] << " \tRK1: " << y1[i] <<" Fu: " << y[i] << " \tabs1: " 
		     << fabs(fInt(x[i]) - y[i])/fabs(fInt(x[i])) << " abs2: "
		     << fabs(fInt(x[i]) - y1[i])/fabs(fInt(x[i])) << endl;
	}
	
	return 0;
}
